package com.theme.passport.service.theme.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.theme.common.mvc.utils.PageUtils;
import com.theme.common.mvc.utils.Query;
import com.theme.passport.dao.theme.UserSignInDao;
import com.theme.passport.entity.theme.UserSignInEntity;
import com.theme.passport.service.theme.UserSignInService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("userSignInService")
public class UserSignInServiceImpl extends ServiceImpl<UserSignInDao, UserSignInEntity> implements UserSignInService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String userId = (String) params.get("userId");
        String startTime = (String) params.get("startTime");
        String endTime = (String) params.get("endTime");
        String todayTime = (String) params.get("todayTime");

        IPage<UserSignInEntity> page = this.page(
                new Query<UserSignInEntity>().getPage(params),
                new QueryWrapper<UserSignInEntity>()
                        .eq(StringUtils.isNotBlank(userId), "user_id", userId)
                        .eq(StringUtils.isNotBlank(todayTime), "sign_in_time", todayTime)
                        .ge(StringUtils.isNotBlank(startTime), "sign_in_time", startTime)
                        .le(StringUtils.isNotBlank(endTime), "sign_in_time", endTime)
                        .orderByAsc("sign_in_time")
        );

        return new PageUtils(page);
    }

}